 package com.yuntongxun.ecdemo.voicechat.util;
 
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 
 /**
  * Md5加密 并作转换
  * @author danny
  *
  */
 public class MD5
 {
   public static String md5s(String plainText)
   {
     try{
    	//根据MD5算法生成MessageDigest对象  
       MessageDigest md5 = MessageDigest.getInstance("MD5");
     //使用srcBytes更新摘要  
       md5.update(plainText.getBytes());
       //完成哈希计算，得到result 
       byte[] resultBytes  = md5.digest();
 
       StringBuffer buf = new StringBuffer("");
       for (int offset = 0; offset < resultBytes .length; offset++) {
         int i = resultBytes[offset];
         if (i < 0){
        	 i += 256;
         }
         if (i < 16){
        	 buf.append("0");
         }
         buf.append(Integer.toHexString(i));
       }
 
       return buf.toString();
     }catch (NoSuchAlgorithmException e) {
       e.printStackTrace();
     }
 
     return null;
   }
 
//   public static void main(String[] agrs) {
//     System.out.println(MD5.md5s("ztq1"));
//   }
 }  